import '../lib/jquery.js'
import { $messageTip, $axios } from './util.js'

const axios = $axios()

// 获取详情
function getDetail() {
  const params = {
    id: window.location.href.split('?')[1].split('=')[1],
  }
  axios.get('/goods/item', { params }).then(res => {
    if (res.data) {
      const data = JSON.parse(res.data)
      if (data.code === 1) {
        const html = `
               <div class="left box">
                <div class="middleBox">
                  <img src="${data.info.img_big_logo}"
                    class="middleimg">
                </div>
              </div>
              <div class="right">
                <p class="title">${data.info.title}</p>
                <p class="price">原价: ¥ <span class="old">${data.info.price}</span></p>
                <p class="price">折扣: <span class="discount">${data.info.sale_type}</span></p>
                <p class="price">现价: ¥ <span class="curprice">${data.info.current_price}</span></p>
              </div>
            `
            $('.content').html(html);
            $('.desc').html(data.info.goods_introduce);
      } else {
        $messageTip(data.message)
      }
    }
  }, err => {
    console.log(err)
  })
}

getDetail()
